const mongoose = require('mongoose')

const fs = require('fs')
mongoose.connect('mongodb://127.0.0.1:27017/test2306')


let db = mongoose.connection

db.once('open', () => {
    console.log('数据库连接成功！')
})


const banners = mongoose.Schema({
    imgname: String,
    imgurl: String,
    status: {
        type: Number,
        enum: [1, 2],
        default: 1   //表示 1 上架  2 下架 
    },
    createTime: {
        type: Date,
        default: new Date()
    }
})

const BannerModel = mongoose.model('banners', banners)



fs.readFile('./banner.json', 'utf-8', (err, data) => {
    let arr = JSON.parse(data)
    console.log(arr)
    arr.forEach(it => {
        new GoodModel(it).save().then(res => {
            console.log('ok')
        })
    })
})